<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
		<title>文件管理</title>
		[#include "/html/include/easyuicss.html" /]
		[#include "/html/include/easyuijs.html" /]
		<script type="text/javascript" src="${app }/static/js/common.utils.js"></script>
	</head>
	<body class="easyui-layout" data-options="fit:true" style="overflow-y: hidden">
	<table id="filedg" class="easyui-datagrid" title="文件信息" style="width:100%;height:100%;">
		<thead>
		<tr>
			<th data-options="field:'attachment_id',width:240">文件编号</th>
			<th data-options="field:'file_name',width:240,formatter:showFileName">文件名称</th>
			<th data-options="field:'attachment_size',width:150">文件大小（MB)</th>
			<th data-options="field:'upload_time',width:150">上传时间</th>
			<th data-options="field:'upload_ip',width:150">上传IP</th>
			<th data-options="field:'operating',width:50,formatter:getBtn">操作</th>
		</tr>
		</thead>
	</table>
	<div id="tb">
		<span>文件名:</span>
		<input  class="easyui-textbox" id="fileName" name="fileName" />
		<span>上传时间:</span>
		<input  class="easyui-datebox" id="startTime" name="startTime" value="${startTime}" />
		<span>至</span>
		<input  class="easyui-datebox" id="endTime" name="endTime" value="${endTime}" />
		<a href="javascript:;" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="searchFiles();">查询</a>
		<a href="javascript:;" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="parent.easyui.createWindow('文件上传', '${app}/sysmgr/file/edit.do', '600px', '450px', window.name);">上传</a>
	</div>
	</body>
    <script type="text/javascript">
		$(document).ready(function(){
			$('#filedg').datagrid({
				url: '${app}/sysmgr/file/list.do',
				method: 'post',
				queryParams: {fileName: $('#fileName').val(), startTime: $('#startTime').val(), endTime: $('#endTime').val()},
				singleSelect: true,
                fitColumns: true,
				toolbar: '#tb',
				onLoadSuccess: onLoadSuccess,
				pagination: true,
				pageSize: 20,
				pageList: [10,20,30]
			});
		});
		function getBtn(value, row, index) {
			return '<a href="javascript:;" class="easyui-linkbutton" onclick="deleteFile(\''+row.attachment_id+'\')">删除</a>&nbsp;';
		}
		function showFileName(value, row, index){
			return '<a href="${app}/sysmgr/file/downloadFile.do?attachmentId='+row.attachment_id+'">'+row.file_name+'</a>';
		}
		function onLoadSuccess(data){
			$('.easyui-linkbutton').linkbutton();
		}
		function searchFiles(){
			$('#filedg').datagrid('load', {
				fileName: $('#fileName').val(),
				startTime: $('#startTime').val(),
				endTime: $('#endTime').val()
			});
		}
		function reloadFiles(){
			$('#filedg').datagrid('reload');
		}
		function deleteFile(attachmentId){
			parent.easyui.confirm('系统提醒', '您确定要删除该条记录吗？', function(r){
				if (r){
					parent.layer.load(2);
					common.ajax('${app}/sysmgr/file/deleteFile.do', 'attachmentId='+attachmentId,
						'POST', 'json', false,
						function(result){
							parent.layer.closeAll('loading');
							parent.easyui.msgShow('系统提醒', result.msg, 3000, 250, 100);
							if (result.result == 1) {
								reloadFiles();
							}
						}
					);
				}
			});
		}
    </script>
</html>